<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/taglib.jsp"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>
    <head>
        <title>系统日志</title>

        <%@include file="/WEB-INF/jsp/include.jsp"%>
        <script type="text/javascript">
            var params = {};
            //var url = path + "/system/ds/queryByCondition";
            //var url = "web/system/ds/queryByCondition";
            // var url = "/queryByCondition";
            var url = '${path}/system/log/queryByPage';
    
            $(function() {
                //设置AjaxLoading
                setAjaxLoading();
                var grid = $("#logtab");
                initGrid(grid);
                btnQuery();
                btnReset();
            });

            //初始化表格和数据
            function initGrid(grid) {
                var columns = [
                    { field: "id", title: "id", hidden:true, align: "center", sortable: false, resizable: true, width: 30},
                    { field: "operator", title: "操作人", align: "center", halign: "center",sortable: false, resizable: true, width: 220},
                    { field: "url", title: "请求路径", align: "center", halign: "center",sortable: false, resizable: true, width: 250},
                    { field: "classMethod", title: "操作类名以及方法", align: "center", halign: "center",sortable: false, resizable: true, width: 200},
                    { field: "paramData", title: "请求参数", align: "center", halign: "center",sortable: false, resizable: true, width: 100},
                    { field: "returnData", title: "返回参数", align: "left", halign: "center",sortable: false, resizable: true, width: 200},
                    { field: "clientIp", title: "操作IP", align: "center", halign: "center",sortable: false, resizable: true, width: 120 },
                    { field: "startTime", title: "请求开始时间", align: "center", halign: "center",sortable: false, resizable: true, width: 150,
                        formatter: function(value, rec) {
                            if (value !=null ) {
                                var date = new Date(value);
                                var year = date.getFullYear();
                                var month = date.getMonth() + 1;
                                var day = date.getDate();
                                var hour = date.getHours();
                                var minute = date.getMinutes();
                                var second = date.getSeconds();
                                return year + '-' + formartVal('0', month) + '-' + formartVal('0', day) + ' ' +
                                    formartVal('0', hour) + ':' + formartVal('0', minute) + ':' + formartVal('0', second);
                            }
                        }},
                    { field: "endTime", title: "请求结束时间", align: "center", halign: "center",sortable: false, resizable: true, width: 150,
                       formatter: function(value, rec) {
                           if (value !=null ) {
                               var date = new Date(value);
                               var year = date.getFullYear();
                               var month = date.getMonth() + 1;
                               var day = date.getDate();
                               var hour = date.getHours();
                               var minute = date.getMinutes();
                               var second = date.getSeconds();
                               return year + '-' + formartVal('0', month) + '-' + formartVal('0', day) + ' ' + 
                               formartVal('0', hour) + ':' + formartVal('0', minute) + ':' + formartVal('0', second);
                            }
                        }
                    },
                    { field: "timeConsuming", title: "执行时间(ms)", align: "center", halign: "center",sortable: false, resizable: true, width: 100},
                    { field: "exceptionMessage", title: "异常信息", align: "center", halign: "center",sortable: false, resizable: true, width: 200},
                    { field: "sessionId", title: "session", align: "center", halign: "center",sortable: false, resizable: true, width: 220}
                ];
                initPageGrid(grid, params, url, columns, "");
                btnQuery();

                var grid_options = $("#logtab").datagrid("options");
                grid_options.onDblClickRow = function(rowIndex, rowData) {
                    viewMessage();
                }
            }
            function formartVal(prefix, val) {
                if(val < 10) {
                    return prefix + val;
                }
                return val;
            }
            // 查询按钮
            function btnQuery() {

                var sTime = $('#startTime').datebox('getValue');
                var eTime =  $('#endTime').datebox('getValue');
                if(sTime != "" ) {
                    var array = sTime.split("-");
                    params.startTime = new Date(array[0], array[1] - 1, array[2]);
                }
                if(eTime != "" ) {
                    var array = eTime.split("-");
                    params.endTime = new Date(array[0], array[1], array[2]);
                }
//                params.startTime = $('#startTime').datebox('getValue');
//                params.endTime = $('#endTime').datebox('getValue');
                params.operator = $('#operator').val();
                params.orderBy =  $("#orderBy").combobox("getValue");
                params.clientIp = $('#clientIp').val();
                params.pageNo = 1;
                var grid = $("#logtab");
                getPage(grid, params, url);
            }
            function viewMessage(){
                var rows = $('#logtab').datagrid('getSelections');
                if (rows.length == 0) {
                    $.messager.alert("操作提示", "请选择一条数据！", "info");
                    return;
                }
                var row = rows[0];
                var id = row.id;
                var url = '${path}/system/log/toView?id='+id;
                var index = top.layer.open({
                    type: 2,
                    title: '查看详细信息',
                    shadeClose: false,
                    shade: [0.8, '#393D49'],//遮罩层
                    maxmin: true,
                    area: ['1000px', '650px'],
                    content: url,
                    success: function(layero, index){

                    },
                    end: function () {
                        btnQuery();
                    }
                });
                top.layer.full(index);
            }

        </script>
        <script type="text/javascript">
            //var curRowIndex;
            //var curRowData;
            //var i_commit = false;

            $(function() {
                //setAjaxLoading();
                //initDatagrid();
                //btnReset();
                //$("#divNorth").prev().find(".layout-button-up").hide();
            });


        //重置
        function btnReset() {
            $('#startTime').datebox('enable');
            $('#endTime').datebox('enable');
            $('#startTime').datebox('setValue', getCurrTimeWeek());
            $('#endTime').datebox('setValue', getCurrTime());
            $('#operator').val("");
            //curRowIndex = -1;
        }

        function getCurrTime(){
            var currentDt = new Date();
            var y = currentDt.getFullYear();
            var m = currentDt.getMonth() + 1;
            if(m < 10) {
                m = "0" + m;
            };
            var d = currentDt.getDate();
            if(d < 10) {
                d = "0" + d;
            }
            var times = y + '-' + m + '-' + d;
            return times;
        }

        function getCurrTimeWeek() {
            var now = new Date();
            var currentDt = new Date(now.getTime() - 6*24*3600*1000);
            var y = currentDt.getFullYear();
            var m = currentDt.getMonth() + 1;
            if( m < 10) {
                m = "0" + m; 
            };
            var d = currentDt.getDate();
            if(d < 10) {
                d = "0" + d;
            }
            var times = y + '-' + m + '-' + d;
            return times;
        }
            /**
             * 格式化气泡显示信息，内容大于19个字显示为 value+“...”
             * @param value
             * @param row
             * @param index
             * @returns {string}
             */
            function remarkFormater(value, row, index) {
                var content = '';
                var abValue = value + '';
                if (value != undefined) {
                    if (value.length >= 25) {
                        abValue = value.substring(0, 22) + "...";
                        content = '<a href="javascript:;"  title="' + value + '" class="">' + abValue + '</a>';
                    } else {
                        content = '<a href="javascript:;"  title="' + abValue + '" class="">' + abValue + '</a>';
                    }
                }
                return content;
            }
        </script>
    </head>
    <body  style="margin:0px; padding:0px;" >
    <%@ include file="/WEB-INF/jsp/loading.jsp" %>
    <div class="easyui-layout" fit="true" >
        <div region="center" style="padding: 5px;" border="false">
            <div class="easyui-layout" fit="true"  border="false">
                <div id="divNorth" region="north"  title="查询条件" style="overflow:hidden;height:71px;padding:6px;background:#EFEFEF;vertical-align:middle;">
                    <table align="left" cellspacing="1" border="0" borderColorDark="#fdfeff" borderColorLight="#99ccff" bgColor="#EFEFEF">
                        <tr>
                            <td>操作时间：</td>
                            <td colspan="2" style="width: 95px;">
                                <input id="startTime" class="easyui-datebox" editable="false" style="width:95px"></input>
                            </td>
                            <td style="text-align:center">至</td>
                            <td colspan="5" style="width: 95px;">
                                <input id="endTime" class="easyui-datebox" editable="false" style="width:95px"></input>
                            </td>
                            <td>操作人：</td>
                            <td><input id="operator" class="text"/></td>
                            <td>
                                操作IP:
                            </td>
                            <td>
                              <td><input id="clientIp" class="text"/></td>
                            </td>
                            <td>排序方式：</td>
                            <td>
                                <select class="easyui-combobox"  id="orderBy" name="orderBy" style="width:200px;">
                                    <option value="START_TIME" selected>操作时间</option>
                                    <option value="TIME_CONSUMING">执行时间</option>
                                    <%--<option value="EXCEPRTION_MESSAGE desc nulls last">异常信息</option>--%>
                                </select>
                            </td>
                            <td colspan="7" align="right">
                                <input class="search-btn-blue" style="margin-left:10px" type="button" onclick="btnQuery();" value="查询">
                                <input class="search-btn-gray" style="margin-left:5px" type="button" onclick="btnReset();" value="重置">
                            </td>
                        </tr>
                        <tr>

                        </tr>
                    </table>
                </div>
                <div id="title_name" region="center" title="列表信息" style="width:100%;background:#fafafa;">
                    <table id="logtab" border="false"></table>
                </div>
            </div>
        </div>
    </div>

  </body>
</html>
